package com.atguigu.ssyx.home.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.*;

/**
 * Created with IntelliJ IDEA.
 * ClassName: ThreadPoolConfig
 * Package: com.atguigu.ssyx.home.config
 * Description:
 * User: fzykd
 *
 * @Author: LQH
 * Date: 2023-10-04
 * Time: 14:48
 */

//配置类 创建线程池对象
@Configuration
public class ThreadPoolConfig {

    @Bean
    public ThreadPoolExecutor threadPoolExecutor(){
        //常用的7个参数
        ThreadPoolExecutor executor = new ThreadPoolExecutor(
                //常驻线程 核心线程
                2,
                //最大线程数
                5,
                //空闲时间
                2,
                //空闲时间的单位
                TimeUnit.SECONDS,
                //阻塞队列
                new ArrayBlockingQueue<>(3),
                //线程工厂
                Executors.defaultThreadFactory(),
                //拒绝策略
                new ThreadPoolExecutor.AbortPolicy()

        );
        return executor;
    }
}
